import { _decorator, color, Color, Component, Enum, Label, Node, Sprite, SpriteFrame, Texture2D, Toggle, Vec3 } from 'cc';
import { Mode, ModeName } from '../enum/Mode';
import { GameMgr } from '../manager/GameMgr';
import { TransMgr } from '../manager/TransMgr';
import { UIMgr } from '../manager/UIMgr';
import { UI } from '../enum/UI';
import { GameUtil, shopData } from '../util/GameUtil';
import { EventMgr } from '../manager/EventMgr';
import { EventType } from '../enum/EventType';
import { AdMgr } from '../manager/AdMgr';
import { DtoLevelData } from '../dto/DtoLevelData';
const { ccclass, property } = _decorator;

@ccclass('UIItem/ShopItem')
export class ShopItem extends Component {

    // @property(Node)
    // private lockBg: Node = null

    // @property({ type: Enum(Mode) })
    // public mode: Mode = Mode.tp

    @property(Label)
    public tileLab: Label = null;

    @property(Label)
    public numLab: Label = null;

    private itemData:DtoLevelData;

    protected onLoad(): void {

    }

    private setData(data:DtoLevelData): void {
        // this.tip.active = false
        // this.btnUnlock.active = false

        this.itemData = data;
        if (!this.itemData){
            return;
        }

        this.tileLab.string = this.itemData.group + "瓶";

        //this.numLab.string = "(" + this.itemData.num + "/" + this.itemData.numMax + ")";

        // if(GameMgr.shopItemArr.indexOf(data.id) >= 0){
        //     GameUtil.loadImage("itemImg/unLock/" + this.itemData.lockImage, this.icon);
        //     this.icon.color = color(255, 255, 255, 255)
        // }else{
        //     GameUtil.loadImage("itemImg/unLock/" + this.itemData.lockImage, this.icon);
        //     this.icon.color = color(60, 60, 60, 255)
        //     //GameUtil.loadImage("itemImg/lock/" + this.itemData.lockImage, this.icon);
        // }

        
        // this.icon.node.active = false;
        // setTimeout(() => {
        //     this.resizeScale();
        // }, 100);
    }

    resizeScale() {  
 
        // let bgSize = this.icon.spriteFrame.getOriginalSize(); // 获取背景图原始大小  
  
        // // 计算缩放比例  
        // let scaleX = 73 / bgSize.width; 
        // let scaleY = 73 / bgSize.height;  
  
        // // 保持宽高比，取较小的缩放比例  
        // const scale = Math.min(scaleX, scaleY);  
  
        // // 设置背景图的缩放  
        // this.icon.node.setScale(scale, scale);  
        // this.icon.node.active = true;
    }

    protected onBtnClick(): void {
        // EventMgr.emit(EventType.OpenUI, UI.ShopDetial, this.itemData, null)
        AdMgr.showRewardedVideo(() => {
            // GameMgr.selectLev = this.itemData.id-1;
            // UIMgr.close(UI.ShopView);   
            // UIMgr.close(UI.Main)
            // GameMgr.startGame()  
        })
    }

}


